package source

import (
	"bytes"
	"io/ioutil"

	"golang.org/x/text/encoding/simplifiedchinese"
	"golang.org/x/text/transform"
)

//Decode 解码:GB2312->UTF-8
func Decode(input []byte) string {
	I := bytes.NewReader(input)
	O := transform.NewReader(I, simplifiedchinese.GBK.NewDecoder())
	d, err := ioutil.ReadAll(O)
	CheckErr(err)
	return string(d)
}

//Encode 编码:UTF-8->GB2312
func Encode(input []byte) string {
	I := bytes.NewReader(input)
	O := transform.NewReader(I, simplifiedchinese.GBK.NewEncoder())
	d, err := ioutil.ReadAll(O)
	CheckErr(err)
	return string(d)
}
